package com.java.function;

import com.java.function.bean.Person;

import java.util.ArrayList;
import java.util.List;

public class Demo {

    public static void main(String[] args) {
        /**
         * 构造引用  方法引用实际上是对lambda表达式的进一步简化
         */
        PersonFactory factory = new PersonFactory(Person::new);
        Person p1 = factory.getPersion();
        p1.setName("Jack");

        List<Person> personList = new ArrayList<>();
        personList.add(p1);

        Person p2 = factory.getPersion();
        p2.setName("Tom");
        personList.add(p2);

        Person p3 = factory.getPersion();
        p3.setName("James");
        personList.add(p3);

        //排序前
        print(personList);


        //静态方法应用
       // personList.sort(Demo::myCompare);


        //特定对象的实例方法
      //  personList.sort(p1::compare);

        //引用某个对象的任意对象的实例方法
        personList.sort(Person::compareTo);
        //排序后
        print(personList);

    }

    private static void print(List<Person> personList) {
        personList.forEach(person -> System.out.print(person.getName() + " "));
        System.out.println();
    }


    private static int myCompare(Person p1,Person p2){
        return p2.getName().compareTo(p1.getName());
    }
}
